/**
 * 
 */
package org.statewalker.tokenizer.base;

import java.util.ArrayList;
import java.util.List;

import org.statewalker.tokenizer.stream.ICharStream;

/**
 * @author kotelnikov
 */
public class CompositeTokenizer<T> implements ITokenizer<T> {

    private List<ITokenizer<T>> fList = new ArrayList<ITokenizer<T>>();

    public void addTokenizer(ITokenizer<T> tokenizer) {
        fList.add(tokenizer);
    }

    public T read(ICharStream stream) {
        for (ITokenizer<T> tokenizer : fList) {
            T token = tokenizer.read(stream);
            if (token != null) {
                return token;
            }
        }
        return null;
    }

    public void removeTokenizer(ITokenizer<T> tokenizer) {
        fList.remove(tokenizer);
    }

}
